#ifndef MAIN_C3LOG_H_
#define MAIN_C3LOG_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <cstring>

#ifndef LOG_TAG
#define LOG_TAG "common"
#endif
void log_tag(const char *Color, const char *TAG, const char *ModuleTAG, const char *format, ...);
void log2file(const char *log_path, bool append, bool ts, const char *format, ...);

#define LOGD(...)                  \
    {                              \
        log_tag("\033[0;36m", "D", LOG_TAG, __VA_ARGS__); \
    }
#define LOGI(...)                  \
    {                              \
        log_tag("\033[0;32m", "I", LOG_TAG, __VA_ARGS__); \
    }
#define LOGW(...)                  \
    {                              \
        log_tag("\033[0;33m", "W", LOG_TAG, __VA_ARGS__); \
    }
#define LOGE(...)                  \
    {                              \
        log_tag("\033[0;31m", "E", LOG_TAG, __VA_ARGS__); \
    }

void read_status(const char *log_path, char *buf, int size);
void print_file(const char *log_path);
int init_log();
int dump_log();
double get_sys_secend();

class CustomLog{
 public:
    FILE *mpLogFD = nullptr;
    char mpLogName[32];
    size_t mLogSize = 0;
    int mNameId = 0;
    int mContentId = 0;
    bool mInited = false;

    static int createNewLogFile(int history_id, int cur_name_id);
};

#endif  // MAIN_C3LOG_H_
